package com.qdevelop.model.service.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import com.qdevelop.model.utils.UtilsFactory;

public class GisSocketClient {
	public String run(String cmd){
		Socket socket=null;
		try {
			socket = new Socket(UtilsFactory.propertiesUtils().getProperty("GIS_SOCKET_SERVER"), 6789);
			BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream())); 
			PrintWriter out=new PrintWriter(socket.getOutputStream()); 
			out.println(cmd); 
			out.flush(); 
			return (in.readLine());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(socket!=null)
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		} 
		return "";
	}
	
	public static void main(String[] args) {
//		System.out.println(new GisSocketClient().run("tranPoint:116.38672,39.90805|116.38672,39.90805"));
//		System.out.println(new GisSocketClient().run("pointToFace:116.38672,39.90805|XingZheng|8"));
		System.out.println(new GisSocketClient().run("keyToPoint:568|JiaoTong|8"));

	}
}
